package com.tongji.housediy.service
{
	/**
	 * 
	 * @author xuxunjia
	 * 
	 */	
	import com.tongji.housediy.events.goodsEvent.GetTypeEvent;
	
	import flash.system.Security;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.robotlegs.mvcs.Actor;
	
	public class TypeService extends Actor
	{
		public var goodsRemoteObject:RemoteObject;
		
		public function TypeService()
		{
			super();
			//var amfChannel:Array = [new AMFChannel(null, "http://10.60.0.118/housediy/Gateway.aspx")];
			var amfChannel:Array = [new AMFChannel(null, "http://design.rryjw.com/Gateway.aspx")];
			//var amfChannel:Array = [new AMFChannel(null, "http://localhost/housediy/Gateway.aspx")];

			var channelSet:ChannelSet = new ChannelSet();
			channelSet.channels = amfChannel;
			
			goodsRemoteObject = new RemoteObject("fluorine");
			goodsRemoteObject.source = "HouseDiyService.HouseDiyAction";
			goodsRemoteObject.showBusyCursor = true;
			goodsRemoteObject.channelSet = channelSet;			
			Security.loadPolicyFile("http://design.rryjw.com/crossdomain.xml");

			goodsRemoteObject.getOperation("getGoodsTypeXml").addEventListener(ResultEvent.RESULT, getGoodsTypeResult);
			goodsRemoteObject.getOperation("getGoodsTypeXml").addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		public function getGoodsType():void
		{
			goodsRemoteObject.getGoodsTypeXml();
		}
		
		private function getGoodsTypeResult(event:ResultEvent):void
		{
			dispatch(new GetTypeEvent(GetTypeEvent.UPDATE_TYPE, event.result as ArrayCollection));
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(" fault :" + event.toString());
		}
	}
}